package com.ly.mpayment.persist.service.sys;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.ly.mpayment.persist.entity.SysConfig;
import com.ly.mpayment.persist.hibernate.Page;
import com.ly.mpayment.persist.service.AbstractService;
@Service
public class SysConfigServiceImpl extends AbstractService<SysConfig, Serializable> implements ISysConfigService{

	@Override
	public List<SysConfig> findAll() {
		return this.find("select s from SysConfig s");
	}

	@Override
	public Page<SysConfig> findPageAll(Map<String, Object> parameters, int start, int pageSize) {
		return this.findPageByNamed("select s from SysConfig s where 1 = 1 #[ and s.attr = :attr ]#  #[ and s.describes = :describes ]#  #[ and s.attrValue = :attrValue ]# order by s.attr ", parameters, start, pageSize);
	}

	@Override
	public boolean saveSysConfig(SysConfig sys) {
		if(sys != null){
			this.saveOrUpdate(sys);
			return true;
		}
		return false;
	}

	@Override
	public boolean updateSysConfig(SysConfig sys) {
		if(sys != null){
			this.updateEntity(sys);
			return true;
		}
		return false;
	}

	@Override
	public SysConfig findById(String id) {
		return this.findUnique("select s from SysConfig s where s.configId = ?", id);
	}

	@Override
	public SysConfig findByAttr(String attr) {
		return this.findUnique("select s from SysConfig s where s.attr = ?", attr);
	}

	@Override
	public boolean deleteConfig(SysConfig config) {
		this.delete(config);
		return true;
	}
}
